package shared;

public class URLList {
	
	//Instance variables
	public String str;
	public URLList nexturl;

	/**
	 * URLList constructor
	 * @param s String
	 * @param url URLList
	 */
    public URLList (String s, URLList url) {
        str = s;
        nexturl = url;
    }
    
    /**
     * toString is called recursively on the list
     */
    public String toString(){
    	//Set the return value to this.str
    	String returnString = str;
    	
    	//Is there exist a next element
    	if(nexturl != null){
    		
    		//Add new line to return value
    		returnString += "\n";
    		
    		//Call toString on next element
    		returnString += nexturl.toString();
    	}    	
    	
    	//Return string
    	return returnString;
    }
    
    /**
     * equals Evaluates if 2 URLList objects are equal
     * 
     * @param o object to evaluate
     */
    public boolean equals (Object o)
    {
    	//Create return value and set it to false
    	boolean returnValue = false;
    	
    	//Check if o is an URLList and not null
    	if(o instanceof URLList && o != null){
    		//Create objects to compare 
    		URLList thisList = this;
    		URLList compareList = (URLList) o;
    		
    		//Check each elements of both lists
    		while(thisList != null && compareList != null){
    			//Assume the return value is true
				returnValue = true;
    			
				//Check if the string is equal
				if(!thisList.str.equals(compareList.str)){
					//Change return value to false and break 
    				returnValue = false;
    				break;
    			} 
				
				//Check the size is the same on both lists
    			if (thisList.nexturl == null && compareList.nexturl != null){
					//Change return value to false and break 
    				returnValue = false;
    				break;
    			}
    			if (thisList.nexturl != null && compareList.nexturl == null){
					//Change return value to false and break 
    				returnValue = false;
    				break;
    			}
    			
    			//Get next element
    			thisList = thisList.nexturl;
    			compareList = compareList.nexturl;
    		}		
    	}    
    	
    	//Return value
    	return returnValue;
    }
}